(function() {"use strict";var __module = CC_EDITOR ? module : {exports:{}};var __filename = 'preview-scripts/assets/Script/StartGameView.js';var __require = CC_EDITOR ? function (request) {return cc.require(request, require);} : function (request) {return cc.require(request, __filename);};function __define (exports, require, module) {"use strict";
cc._RF.push(module, '1cecaG33C5HDrdnZIQ2fR1G', 'StartGameView', __filename);
// Script/StartGameView.js

"use strict";

var _PlatformUtil = require("./PlatformUtil");

var _PlatformUtil2 = _interopRequireDefault(_PlatformUtil);

var _NumberView = require("./NumberView");

var _NumberView2 = _interopRequireDefault(_NumberView);

var _allVariable = require("./allVariable");

var _allVariable2 = _interopRequireDefault(_allVariable);

var _XmlHttpTool = require("./XmlHttpTool");

var _XmlHttpTool2 = _interopRequireDefault(_XmlHttpTool);

var _xor = require("./Tool/xor");

var _xor2 = _interopRequireDefault(_xor);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

cc.Class({

    extends: cc.Component,

    properties: {

        startGameBtn: cc.Button,
        numberCompontent: _NumberView2.default,
        energyCompontent: _NumberView2.default,
        bgMusicSound: {
            default: null,
            type: cc.AudioClip
        },
        topView: cc.Node,
        logonode: cc.Node,
        wordListView: cc.Node,
        friendListView: cc.Node,
        bageAllScrollView: cc.Node,
        inviteBtn: cc.Button,
        rankBtn: cc.Button,
        moreBtn: cc.Button,
        shopBtn: cc.Button,
        moreContentView: cc.Node,
        userEnergy: cc.Integer,
        showHubProjess: cc.Node,
        SvprogressPrefab: cc.Prefab,
        brannerAdmessage: "",
        videoBtn: cc.Button,
        chooseMarkView: cc.Node,
        taskBtn: cc.Button,
        gameBoxBtn: cc.Button,
        taskListView: cc.Node,
        taskContentListView: cc.Node,
        boxLayout: cc.Node,
        isOpenBox: cc.Boolean,
        taskThint: cc.Node,
        bageThink: cc.Node,
        moneytip: cc.Node

    },

    enterGameViewClick: function enterGameViewClick() {

        if (this.userEnergy > 0) {

            var changebig2 = cc.scaleTo(0.2, 1.1);

            var finish = cc.callFunc(function () {

                var changesmail2 = cc.scaleTo(0.1, 1.0);
                this.startGameBtn.node.runAction(changesmail2);
            }, this);

            var seq = cc.sequence(changebig2, finish);

            this.startGameBtn.node.runAction(seq);

            cc.director.loadScene("GameSence", function () {

                var mainNode = cc.find("Canvas/backgroundtop");

                mainNode.getComponent("backgrould").onAgainSence();
            });
        } else {

            this.chooseMarkView.active = true;
            this.videoBtn.node.active = true;
            // if(cc.isValid(this.showHubProjess)){
            //     this.showHubProjess.destroy();
            //   }
            //   this.showHubProjess = cc.instantiate(this.SvprogressPrefab);
            //   this.node.addChild(this.showHubProjess);
            //   this.showHubProjess.getComponent('SVProgressView').init("体力不足,无法开始游戏")

            //    let finish = cc.callFunc(() => { 

            //     this.showHubProjess.destroy();

            //   }, this);
            // let action = cc.sequence(cc.fadeIn(0.6), cc.delayTime(0.5), cc.fadeOut(1), finish);
            // this.showHubProjess.runAction(action);
        }
    },

    videoStartClick: function videoStartClick() {
        var _this2 = this;

        this.chooseMarkView.active = false;
        this.videoBtn.node.active = false;
        var _this = this;
        if (_allVariable2.default.allvideoAD) {

            _allVariable2.default.allvideoAD.offClose();
            _allVariable2.default.allvideoAD.offError();
            _allVariable2.default.allvideoAD.onClose(function (res) {
                if (res && res.isEnded || res === undefined) {
                    var that = _this2;
                    _XmlHttpTool2.default.httpPost("/marmot/ads_to_energy", {}, function (res) {
                        console.log("正常播放,可以发游戏奖励", res);
                        var flagstr = res.flag_key + _PlatformUtil2.default.platform.params["appver"];
                        var resultstr = _xor2.default.encryptionData(flagstr, _PlatformUtil2.default.platform.params);
                        _XmlHttpTool2.default.NhttpPost("/marmot/ads_to_energy", { "flag_key": resultstr, "keysid": res.keysid }, function (res) {
                            console.log("广告体力请求接口", res);
                            that.energyCompontent.setText(parseInt(res["energy"]));
                            that.userEnergy = parseInt(res["energy"]);
                        });
                    });
                } else {
                    // 播放中途退出，不下发游戏奖励
                    console.log("播放中途退出，不下发游戏奖d励", res);
                }
            });

            _allVariable2.default.allvideoAD.onError(function (res) {

                var errcode = res["errCode"];
                _this.tishifinde();
                if (errcode == 1004) {
                    console.log("无广告资源");
                } else {
                    console.log("无广告资源");
                }
            });

            _allVariable2.default.allvideoAD.load(function (res) {
                console.log('激励视频 广告加载成功', res);
            }).then(function () {
                return _allVariable2.default.allvideoAD.show();
            }).catch(function (err) {
                console.log('激励视频抓取结果', err);
                _this.tishifinde();
            });
        } else {

            var that = this;
            var rewardedVideoAd = wx.createRewardedVideoAd({

                adUnitId: 'adunit-8536f460f8a4925c'

            });
            _allVariable2.default.allvideoAD = rewardedVideoAd;
            _allVariable2.default.allvideoAD.offClose();
            _allVariable2.default.allvideoAD.onClose(function (res) {
                if (res && res.isEnded || res === undefined) {
                    var that = _this2;
                    _XmlHttpTool2.default.httpPost("/marmot/ads_to_energy", {}, function (res) {
                        console.log("正常播放,可以发游戏奖励", res);
                        var flagstr = res.flag_key + _PlatformUtil2.default.platform.params["appver"];
                        var resultstr = _xor2.default.encryptionData(flagstr, _PlatformUtil2.default.platform.params);
                        _XmlHttpTool2.default.NhttpPost("/marmot/ads_to_energy", { "flag_key": resultstr, "keysid": res.keysid }, function (res) {
                            console.log("广告体力请求接口", res);
                            that.energyCompontent.setText(parseInt(res["energy"]));
                            that.userEnergy = parseInt(res["energy"]);
                        });
                    });
                } else {
                    // 播放中途退出，不下发游戏奖励
                    console.log("播放中途退出，不下发游戏奖d励", res);
                }
            });

            _allVariable2.default.allvideoAD.onError(function (res) {

                var errcode = res["errCode"];
                that.tishifinde();
                if (errcode == 1004) {

                    console.log("无广告资源");
                } else {
                    console.log("无广告资源");
                }
            });
            _allVariable2.default.allvideoAD.load(function (res) {
                console.log('激励视频 广告加载成功', res);
            }).then(function () {
                return _allVariable2.default.allvideoAD.show();
            }).catch(function (err) {
                console.log('激励视频抓取结果', err);
                that.tishifinde();
            });
        }
    },

    tishifinde: function tishifinde() {
        var _this3 = this;

        if (cc.isValid(this.showHubProjess)) {
            this.showHubProjess.destroy();
        }
        this.showHubProjess = cc.instantiate(this.SvprogressPrefab);
        this.node.addChild(this.showHubProjess);
        this.showHubProjess.getComponent('SVProgressView').init("今天的广告已经看完了哦！");

        var finish = cc.callFunc(function () {

            _this3.showHubProjess.destroy();
        }, this);
        var action = cc.sequence(cc.fadeIn(0.6), cc.delayTime(3), cc.fadeOut(1), finish);
        this.showHubProjess.runAction(action);
    },

    onLoad: function onLoad() {

        var that = this;

        cc.loader.load({ url: "https://h5.taoqi001.com/minigames/mouse_click/mouseImage/invites.png", type: 'png' }, function (err, img) {
            var mylogo = new cc.SpriteFrame(img);

            that.inviteBtn.node.getComponent(cc.Sprite).spriteFrame = mylogo;
        });

        var system = wx.getSystemInfoSync();
        var width = system.screenWidth;
        var height = system.screenHeight;

        this.isOpenBox = false;

        console.log("屏幕宽与高", width, height);
        _PlatformUtil2.default.init();

        _PlatformUtil2.default.platform.init(this);

        _PlatformUtil2.default.platform.getStorage("wxtoken");

        window["httppost"] = _XmlHttpTool2.default;

        console.log("全局", window["httppost"]);

        console.log("取出缓存的token", _PlatformUtil2.default.platform.getStorage("wxtoken"));

        this.getUserInfoMessage();

        if (_PlatformUtil2.default.platform.getStorage("wxtoken")) {

            _PlatformUtil2.default.platform.checkSession();
        } else {
            console.log("第一次登录");
            this.loginGame();
        }

        _PlatformUtil2.default.platform.loadSuccess();

        if (_allVariable2.default.isMusicPlaying) {} else {

            var isSwitchSound = _PlatformUtil2.default.platform.enableBGM();

            console.log("设备类型", cc.sys.os);

            switch (cc.sys.os) {
                case cc.sys.OS_ANDROID:
                    if (isSwitchSound) {
                        this.current = cc.audioEngine.play(this.bgMusicSound, true, 1);
                    }
                    break;
                case cc.sys.OS_IOS:
                    this.current = cc.audioEngine.play(this.bgMusicSound, true, 1);
                    break;

                default:
                    this.current = cc.audioEngine.play(this.bgMusicSound, true, 1);
                    break;

            }

            _allVariable2.default.isMusicPlaying = true;
        }

        console.log("播放后的音频", this.current);

        this.isIphoneX = _PlatformUtil2.default.platform.isFullScreen();

        this.logonode.active = true;

        var that = this;

        cc.loader.load({ url: "https://h5.taoqi001.com/upload/201901/b0b9b7ee3b07972bd1d309c7e38eb9cc67e28ff7.png", type: 'png' }, function (err, img) {

            var mylogo = new cc.SpriteFrame(img);

            that.logonode.getComponent(cc.Sprite).spriteFrame = mylogo;
        });

        var changebig2 = cc.scaleTo(0.2, 1.2);

        var finish = cc.callFunc(function () {

            var changesmail2 = cc.scaleTo(0.1, 1.0);
            this.logonode.runAction(changesmail2);
        }, this);

        var seq = cc.sequence(changebig2, finish);

        this.logonode.runAction(seq);

        if (height == 812) {} else {

            var that = this;
            cc.loader.load({ url: "https://h5.taoqi001.com/upload/201812/51308ffe7e23853bfd178b290cb53ab9c7ec6128.jpg", type: 'png' }, function (err, img) {

                var mylogo = new cc.SpriteFrame(img);

                that.node.getComponent(cc.Sprite).spriteFrame = mylogo;
                that.node.height = 1624;
            });

            that.topView.y = 607;
            this.logonode.y = 200;
        }

        if (_allVariable2.default.allbrannerAD) {
            console.log("不要创建branner广告了");
        } else {

            var bannerAd = wx.createBannerAd({
                adUnitId: 'adunit-d7f07be21319bd0b',
                style: {
                    left: 0,
                    top: 0,
                    width: width
                }
            });

            bannerAd.onResize(function (res) {

                console.log("广告位置", res.width, res.height);
                bannerAd.style.top = height - res.height;
                bannerAd.style.left = 0;
                bannerAd.style.width = width;
            });
            _allVariable2.default.allbrannerAD = bannerAd;
            _allVariable2.default.allbrannerAD.onError(function (res) {

                console.log('广告错误', res);
            });
        }

        _allVariable2.default.allbrannerAD.show();

        var animState = this.moneytip.getComponent(cc.Animation);

        animState.playAdditive("tips");

        var animtip = animState.getAnimationState('tips');

        // // 设置循环模式为 Loop
        animtip.wrapMode = cc.WrapMode.Loop;

        // 设置动画循环次数为无限次
        animtip.repeatCount = Infinity;
    },


    loginGame: function loginGame() {

        var _this = this;

        _PlatformUtil2.default.platform.getWeXinToken(function (rescode) {

            _XmlHttpTool2.default.getTokenPost("/users/wxregister", { "regtype": 1, "code": rescode }, function (res) {

                console.log("获取token请求", res);

                _PlatformUtil2.default.platform.setStorage({ 'key': "wxtoken", 'value': res["token"] });

                _PlatformUtil2.default.platform.getWeXinUserInfo(function (userInfo) {

                    console.log("传过来的用户信息", userInfo);
                });

                _this.loginMouse();
            });
        });
    },

    taskClick: function taskClick() {

        var changebig2 = cc.scaleTo(0.2, 1.1);

        var finish = cc.callFunc(function () {

            var changesmail2 = cc.scaleTo(0.1, 1.0);
            this.taskBtn.node.runAction(changesmail2);
        }, this);

        var seq = cc.sequence(changebig2, finish);

        this.taskBtn.node.runAction(seq);

        this.taskListView.active = true;
        this.taskContentListView.getComponent("taskScrollview").init();
    },

    gameBoxClick: function gameBoxClick() {

        if (this.isOpenBox == false) {
            this.boxLayout.active = true;
            this.boxLayout.getComponent("boxLayout").init();
            this.isOpenBox = true;
        } else {
            this.boxLayout.active = false;
            this.isOpenBox = false;
        }

        var changebig2 = cc.scaleTo(0.2, 1.1);

        var finish = cc.callFunc(function () {

            var changesmail2 = cc.scaleTo(0.1, 1.0);
            this.gameBoxBtn.node.runAction(changesmail2);
        }, this);

        var seq = cc.sequence(changebig2, finish);

        this.gameBoxBtn.node.runAction(seq);

        // if(cc.isValid(this.showHubProjess)){
        //     this.showHubProjess.destroy();
        //   }
        //   this.showHubProjess = cc.instantiate(this.SvprogressPrefab);
        //   this.node.addChild(this.showHubProjess);
        //   this.showHubProjess.getComponent('SVProgressView').init("暂未开放,敬请期待...")

        //    let finish = cc.callFunc(() => { 

        //     this.showHubProjess.destroy();
        //   }, this);
        // let action = cc.sequence(cc.fadeIn(0.6), cc.delayTime(0.5), cc.fadeOut(1), finish);
        // this.showHubProjess.runAction(action);

    },

    getUserInfoMessage: function getUserInfoMessage() {

        var that = this;
        _XmlHttpTool2.default.NhttpPost("/marmot/user_info", {}, function (res) {

            console.log("用户信息", res);

            var stars = parseInt(res["ticket_num"]);
            var energy = parseInt(res["energy_num"]);
            if (parseInt(res["wechat_money"]) >= 10) {
                that.bageThink.active = true;
            }
            that.userEnergy = energy;
            that.numberCompontent.setText(stars);
            that.energyCompontent.setText(energy);
        });

        _XmlHttpTool2.default.NhttpPost("/users/login", {}, function (res) {

            console.log("送体力", res);
        });
    },

    loginMouse: function loginMouse() {

        console.log("确认的字典", _PlatformUtil2.default.platform.params);
        this.getUserInfoMessage();
        this.notifyPrize();
        this.startGameBtn.node.active = true;
        this.topView.getChildByName("scoreShow").active = true;
        // this.topView.getChildByName("chargeBtn").active=true
        this.node.getChildByName("shopBtn").active = true;
    },

    notifyPrize: function notifyPrize() {

        var that = this;
        _XmlHttpTool2.default.NhttpPost("/marmot/notify_prize", {}, function (res) {

            console.log("未领奖任务", res);
            if (res == true) {
                that.taskThint.active = true;
            } else {
                that.taskThint.active = false;
            }
        });
    },

    refreCoinClick: function refreCoinClick() {

        //     var that= this
        //    httpUtils.NhttpPost("/users/stars",{},function(res){

        //     var stars =parseInt(res["stars"])

        //     that.numberCompontent.setText(stars)

        //    },function(failres){
        //     console.log('刷新金币错误',failres)
        //    }
        //    )

    },

    inviteShare: function inviteShare() {

        console.log("邀请好友一起玩");
        _allVariable2.default.iswatchAd = false;
        var that = this;
        _XmlHttpTool2.default.NhttpPost("/wxmp/marmot/share_msg", {}, function (res) {

            console.log('分享成功', res);

            var changebig2 = cc.scaleTo(0.2, 1.1);

            var finish = cc.callFunc(function () {

                var changesmail2 = cc.scaleTo(0.1, 1.0);
                that.inviteBtn.node.runAction(changesmail2);
                _PlatformUtil2.default.platform.wxShareMessage(res, function (sharessmessage) {
                    console.log("最多加三个体力", sharessmessage);

                    if (cc.isValid(that.showHubProjess)) {
                        that.showHubProjess.destroy();
                    }
                    that.showHubProjess = cc.instantiate(that.SvprogressPrefab);
                    that.node.addChild(that.showHubProjess);
                    that.showHubProjess.getComponent('SVProgressView').init(sharessmessage["tip"]);

                    var finish = cc.callFunc(function () {

                        that.showHubProjess.destroy();
                    }, that);
                    var action = cc.sequence(cc.fadeIn(0.6), cc.delayTime(0.5), cc.fadeOut(1), finish);
                    that.showHubProjess.runAction(action);
                });
            }, that);

            var seq = cc.sequence(changebig2, finish);

            that.inviteBtn.node.runAction(seq);
        }, function (failres) {});
    },

    rankView: function rankView() {

        console.log("排行榜");

        var changebig2 = cc.scaleTo(0.2, 1.1);

        var finish = cc.callFunc(function () {

            var changesmail2 = cc.scaleTo(0.1, 1.0);
            this.rankBtn.node.runAction(changesmail2);
            this.friendListView.active = true;
        }, this);

        var seq = cc.sequence(changebig2, finish);

        this.rankBtn.node.runAction(seq);
    },

    bageView: function bageView() {

        console.log("兑换包裹");
    },

    moreView: function moreView() {

        console.log("更多");

        var changebig2 = cc.scaleTo(0.2, 1.1);

        var finish = cc.callFunc(function () {

            var changesmail2 = cc.scaleTo(0.1, 1.0);
            this.moreBtn.node.runAction(changesmail2);
            this.moreContentView.getComponent("bageScrollView").init();
            this.bageAllScrollView.active = true;
        }, this);

        var seq = cc.sequence(changebig2, finish);

        this.moreBtn.node.runAction(seq);
    },

    start: function start() {}
});

cc._RF.pop();
        }
        if (CC_EDITOR) {
            __define(__module.exports, __require, __module);
        }
        else {
            cc.registerModuleFunc(__filename, function () {
                __define(__module.exports, __require, __module);
            });
        }
        })();
        //# sourceMappingURL=StartGameView.js.map
        